import React from 'react'
import { connect } from 'dva'
import Com from '../components/Com'

function HomePage({ title, dispatch, list }) {
    console.log(list)
    return (
        <div>
            <Com/>
            <h3>
                我是Home页面 -- {title}
            </h3>
            <button onClick={() => {
                dispatch({ type: "home/changeTitle" })
            }}>
                触发
            </button>

            <button onClick={() => {
                dispatch({ type: "home/init" })
            }}>
                发起异步任务
            </button>
            <ul>
                {
                    list.map((item, index) => {
                        return <img key={ index } src={ item.image_src }/>
                    })
                }
            </ul>
        </div>
    )
}

const mapStateToProps = (state) => {
    const { home } = state
    const { title, list } = home
    return {
        title,
        list
    }
}

export default connect(mapStateToProps)(HomePage)
